package com.example.mapper;


import com.example.entity.FinanceRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FinanceRecordMapper {

    @Insert("INSERT INTO finance_records (user_id, category, amount, record_time, description) " +
            "VALUES (#{userId}, #{category}, #{amount}, NOW(), #{description})")
    int insertFinanceRecord(FinanceRecord record);

    @Delete("DELETE FROM finance_records WHERE record_id = #{recordId}")
    int deleteFinanceRecordById(Integer recordId);

    @Update("UPDATE finance_records SET category = #{category}, amount = #{amount}, description = #{description} " +
            "WHERE record_id = #{recordId}")
    int updateFinanceRecord(FinanceRecord record);

    @Select("SELECT * FROM finance_records WHERE user_id = #{userId} ORDER BY record_time DESC")
    List<FinanceRecord> getFinanceRecordsByUserId(Integer userId);
}

